<?php
class JobsFForm extends BaseFormAdmin{
	public function configure(){
		
		$recruiting = AdminArrayData::getRecruiting();
		$arrYear = array();
		$gender = AdminArrayData::getGender();
		
		
		$this->setWidgets(array(
				'company_id'		=> new sfWidgetFormDoctrineChoice(array(
						'model' 		=> 'Companies',
						'query'			=> Doctrine_Query::create()
											->select('c.id, c.company_name as name')
											->from('Companies c')
											->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)')
											->orderBy('name asc'),
						'multiple' 		=> false,
						'add_empty' 	=> __('option_select', null, 'table_list'))),
				'position_id'		=> new sfWidgetFormDoctrineChoice(array(
						'model' 		=> 'CompanyPersonContactPositions',
						'query'			=> Doctrine_Query::create()
											->from('CompanyPersonContactPositions c')
											->select('c.id, c.name')
											->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)')
											->orderBy('c.name asc'),
						'multiple' 		=> false,
						'add_empty' 	=> __('option_select', null, 'table_list'))),
				'title'						=> new sfWidgetFormInputText(),
				'short_description' 		=> new sfWidgetFormTextarea(),
				'description' 				=> new sfWidgetFormTextarea(),
				'date_from'					=> new sfWidgetFormInputText,//(array('format'=>'%year%-%month%-%day%', 'years' => $arrYear)),
				'date_to'					=> new sfWidgetFormInputText, //sfWidgetFormDate(array('format'=>'%year%-%month%-%day%', 'years' => $arrYear)),
				'number_recruitment'			=> new sfWidgetFormInputText(),
				'number_recruited'				=> new sfWidgetFormInputText(),
				'require_year_experience'		=> new sfWidgetFormInputText(),
				'require_description'			=> new sfWidgetFormTextarea(),
				
				'require_gender'				=> new sfWidgetFormChoice(array('choices'=>$gender,'expanded'=>true)),
				'probation_time'				=> new sfWidgetFormInputText(),
				'probation_salary'				=> new sfWidgetFormInputText(),
				'benefit'						=> new sfWidgetFormTextarea(),
				'major_text'					=> new sfWidgetFormInputText(),
				
				'salary_payed'			=> new sfWidgetFormInputText(),
				'salary_from'			=> new sfWidgetFormInputText(),
				'salary_to'				=> new sfWidgetFormInputText(),
				'age_from'				=> new sfWidgetFormChoice(array('choices'=>AdminArrayData::getAgeRange(),'expanded'=>false)),
				'age_to'				=> new sfWidgetFormChoice(array('choices'=>AdminArrayData::getAgeRange(),'expanded'=>false)),
				'is_recruit'			=> new sfWidgetFormChoice(array('choices'=>$recruiting,'expanded'=>true)),
				
		));

		$this->setValidators(array(
				'company_id'       	=> new sfValidatorDoctrineChoice(array(
						'model' => 'Companies',
						'query' => Doctrine_Query::create()
									->select('c.id, c.company_name as name')
									->from('Companies c')
									->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)'),
						'required' => true),
						array('required'=> 'input company_id')),
				'position_id'       	=> new sfValidatorDoctrineChoice(array(
						'model' => 'CompanyPersonContactPositions',
						'query' => Doctrine_Query::create()
									->select('c.id, c.name')
									->from('CompanyPersonContactPositions c')
									->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)'),
						'required' => true),
						array('required'=> 'input position_id')),
				'title'						=> new sfValidatorString(array('max_length' => 255, 'required' => true)),
				'short_description' 		=> new sfValidatorString(array('required' => false)),
				'description' 				=> new sfValidatorString(array('required' => false)),
				'date_from'					=> new sfValidatorString(array('required'=>false)),
				'date_to'					=> new sfValidatorString(array('required'=>false)),
				'number_recruitment'			=> new  sfValidatorString(array('required' => false)),
				'number_recruited'				=> new  sfValidatorString(array('required' => false)),
				'require_year_experience'		=> new  sfValidatorString(array('required' => false)),
				'require_description'			=> new  sfValidatorString(array('required' => false)),
				
				'require_gender'			=> new sfValidatorChoice(array('choices'=>array_keys($gender))),
				'probation_time'			=> new  sfValidatorString(array('required' => false)),
				'probation_salary'			=> new  sfValidatorString(array('required' => false)),
				'benefit'					=> new  sfValidatorString(array('required' => false)),
				'major_text'				=> new  sfValidatorString(array('required' => false)),
				
				'salary_payed'			=> new  sfValidatorString(array('required' => false)),
				'salary_from'			=> new sfValidatorString(array('required' => false)),
				'salary_to'				=> new sfValidatorString(array('required' => false)),
				'age_from'				=> new sfValidatorChoice(array('choices'=>array_keys(AdminArrayData::getAgeRange()))),
				'age_to'				=> new sfValidatorChoice(array('choices'=>array_keys(AdminArrayData::getAgeRange()))),
				'is_recruit'			=> new sfValidatorChoice(array('choices'=>array_keys($recruiting))),
		));
		
		parent::configure();
		
		$this->setDefault('salary_from', '0');
		$this->setDefault('salary_to', '0');
		$this->setDefault('salary_payed', '0');
		$this->setDefault('age_from', '14');
		$this->setDefault('age_to', '30');
		$this->setDefault('is_recruit', '1');
		$this->setDefault('require_year_experience', '0');
		$this->setDefault('number_recruitment', '0');
		$this->setDefault('number_recruited', '0');
		$this->setDefault('require_gender', '-1');
		$this->setDefault('probation_time', '0');
		$this->setDefault('probation_salary', '100');
		/*
		 * Setting name of form
		*/
		$this->widgetSchema->setNameFormat('Jobs[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
	
}
